package org.dtrd.modules.doctor.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.dtrd.modules.doctor.entity.bean.*;
import org.dtrd.modules.doctor.entity.po.DtrdRlDoctorPatient;
import org.dtrd.modules.patient.entity.bean.PatientH5ListInfo;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 医生-患者服务类
 * </p>
 *
 * @author QR
 * @since 2021-12-17
 */
public interface IDtrdRlDoctorPatientService extends IService<DtrdRlDoctorPatient> {

    List<DoctorPatientListInfo> getDoctorPatientList(DoctorPatientListRequest request);

    IPage<DoctorPatientListInfo> pageDoctorPatient(DoctorPatientPageRequest request);

    List<Integer> listPatientIdsByDoctorId(Integer doctorId);

    List<Integer> listPatientIdsByDoctorId(List<Integer> doctorIdList);

    /**
     * 通过 patientId 获取 doctorId
     */
    Integer getDoctorIdByPatientId(Integer patientId);

    DoctorPatientDetail getDoctorPatient(Integer dataId);

    boolean saveOrUpdateDoctorPatient(DoctorPatientDetail dto);

    boolean removeDoctorPatient(Integer dataId);

    /**
     * 获取医生某个分组的患者人数
     */
    Integer countDoctorGroupPatient(Integer doctorId, Integer groupId);

    /**
     * 更新或保存医患关系记录
     *
     * @return
     */
    boolean saveOrUpdateDoctorPatientRelation(Integer doctorId, Integer patientId, int relationType);

    Map<Integer, Integer> getPatientIdToDoctorIdMap(List<Integer> patientIds);

    List<PatientServiceInfo> getPatientInfomationInDoctorService(List<Integer> doctorIdList, Integer packageId);

    String getChatroomIdByPatientId(Integer patientId, Integer doctorId);

    /**
     * 关注或取关患者
     *
     * @param doctorId
     * @param patientId
     * @param patientsCollected
     * @return
     */
    boolean concernPatient(Integer doctorId, Integer patientId, Integer patientsCollected);

    List<DtrdRlDoctorPatient> getRelativeRecords();

    void onSugarRecord(Integer patientId, Integer dataId, Date recordDate);

    /**
     * 查询医生-今日测量、未测量、扫码患者数
     *
     * @param doctorId
     * @return
     */
    int[] getH5Statistics(Integer doctorId);

    /**
     * 查询医生扫码患者数
     *
     * @param doctorId
     * @return
     */
    List<DoctorStatisticsItem> getScanPatientStatistics(Integer doctorId, String orgCode);

    List<DoctorStatisticsItem> getScanPatientStatisticsV2(List<Integer> teamDoctorIdList);

    List<DoctorStatisticsItem> getPatientStatisticsV2(List<Integer> teamDoctorIdList);

    /**
     * 统计医生所有患者数
     *
     * @param doctorId
     * @param orgCode
     * @return
     */
    List<DoctorStatisticsItem> getPatientStatistics(Integer doctorId, String orgCode);

    /**
     * 分页查询重点关注患者列表
     *
     * @param doctorId
     * @param pageNum
     * @param pageSize
     * @return
     */
    IPage<PatientH5ListInfo> pageConcernPatientList(Integer doctorId, Integer pageNum, Integer pageSize);

    /**
     * 分页查询今日测量、未测量、扫码患者列表
     *
     * @param doctorIdList
     * @param pageNum
     * @param pageSize
     * @param doctorId
     * @return
     */
    IPage<PatientH5ListInfo> pageRelationPatientList(List<Integer> doctorIdList, @NotNull Integer doctorId, Integer type, Integer subType, Integer pageNum, Integer pageSize);

    /**
     * 删除患者时删除医患关联记录与重点关注记录
     *
     * @param patientIds
     */
    void deleteRecordByPatientIds(Set<Integer> patientIds);

    /**
     * 计算医生服务中患者总数
     *
     * @param doctorId
     * @return
     */
    List<DoctorStatisticsItem> countServingPatient(Integer doctorId);

    /**
     * 计算医生服务中患者总数
     *
     * @param doctorIdList
     * @return
     */
    List<DoctorStatisticsItem> countServingPatientV2(List<Integer> doctorIdList);

    /**
     * 计算联网血糖仪患者数
     *
     * @param doctorId
     * @return
     */
    List<DoctorStatisticsItem> countBindDevicePatient(Integer doctorId);

    /**
     * 计算联网血糖仪患者数
     *
     * @param doctorIdList
     * @return
     */
    List<DoctorStatisticsItem> countBindDevicePatientV2(List<Integer> doctorIdList);

}
